package org.springblade.modules.repair.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.repair.dto.PlanContentStatisticalSearchDTO;
//import org.springblade.modules.repair.service.IMaintainGroupService;
import org.springblade.modules.repair.service.PlanContentStatisticalService;
import org.springblade.modules.repair.vo.plan.PlanContentStatisticalResultVo;
import org.springblade.modules.repair.vo.plan.PlanContentStatisticalVo;
import org.springblade.modules.system.entity.UserInfo;
import org.springblade.modules.system.service.IUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 维保任务统计相关
 *
 * @author zcc
 * @version 1.0
 * @date 2022/1/4 14:37
 */
@RestController
@AllArgsConstructor
@RequestMapping("repair/plan/content/statistical")
@Api(value = "维保任务统计管理", tags = "维保任务统计管理")
public class PlanContentStatisticalController {


	private final PlanContentStatisticalService planContentStatisticalService;

//	private final IMaintainGroupService maintainGroupService;

	private final IUserService userService;

//	/**
//	 * 自定义分页 维保任务表
//	 */
//	@PostMapping("/getPlanContentStatisticalInfo")
//	@ApiOperation(value = "获取保养统计信息")
//	public R<PlanContentStatisticalVo> getPlanContentStatisticalInfo(@RequestBody PlanContentStatisticalSearchDTO planContentStatisticalSearchDTO) {
//		UserInfo userInfo = userService.getuserGroupInfo(AuthUtil.getUserId());
//		List<Long> groupIds = new ArrayList<>();
//		groupIds.add(userInfo.getMaintainGroupId());
//		planContentStatisticalSearchDTO.setUserId(AuthUtil.getUserId());
//		//判断是否是组长角色，获取所有的组
//		if (userInfo.getGroupLeader() == 1) {
//			List<Long> childGroupIds = maintainGroupService.getChildGroupIds(userInfo.getMaintainGroupId());
//			groupIds.addAll(childGroupIds);
//			planContentStatisticalSearchDTO.setUserId(null);
//		}
//		planContentStatisticalSearchDTO.setGroupIds(groupIds);
//		String startDate = planContentStatisticalSearchDTO.getStartDate();
//		if (StrUtil.isEmpty(startDate)) {
//			planContentStatisticalSearchDTO.setStartDate(DateUtil.format(DateUtil.beginOfMonth(new Date()), "yyyy-MM-dd"));
//			planContentStatisticalSearchDTO.setEndDate(DateUtil.format(DateUtil.endOfMonth(new Date()), "yyyy-MM-dd"));
//		}
//		PlanContentStatisticalVo planContentStatisticalVo = planContentStatisticalService.getPlanContentStatisticalInfo(planContentStatisticalSearchDTO);
//		return R.data(planContentStatisticalVo);
//	}
//
//
//	/**
//	 * 自定义分页 维保任务表
//	 */
//	@PostMapping("/getPlanContentStatisticalDetail")
//	@ApiOperation(value = "获取保养列表")
//	public R<PlanContentStatisticalResultVo> getPlanContentStatisticalDetail(@RequestBody PlanContentStatisticalSearchDTO planContentStatisticalSearchDTO) {
//		UserInfo userInfo = userService.getuserGroupInfo(AuthUtil.getUserId());
//		List<Long> groupIds = new ArrayList<>();
//		groupIds.add(userInfo.getMaintainGroupId());
//		planContentStatisticalSearchDTO.setUserId(AuthUtil.getUserId());
//		//判断是否是组长角色，获取所有的组
//		if (userInfo.getGroupLeader() == 1) {
//			List<Long> childGroupIds = maintainGroupService.getChildGroupIds(userInfo.getMaintainGroupId());
//			groupIds.addAll(childGroupIds);
//			planContentStatisticalSearchDTO.setUserId(null);
//		}
//		planContentStatisticalSearchDTO.setGroupIds(groupIds);
//		String startDate = planContentStatisticalSearchDTO.getStartDate();
//		if (StrUtil.isEmpty(startDate)) {
//			planContentStatisticalSearchDTO.setStartDate(DateUtil.format(DateUtil.beginOfMonth(new Date()), "yyyy-MM-dd"));
//			planContentStatisticalSearchDTO.setEndDate(DateUtil.format(DateUtil.endOfMonth(new Date()), "yyyy-MM-dd"));
//		}
//		PlanContentStatisticalResultVo planContentStatisticalDetail = planContentStatisticalService.getPlanContentStatisticalDetail(planContentStatisticalSearchDTO);
//		return R.data(planContentStatisticalDetail);
//	}

}
